package or;

import org.junit.jupiter.api.Test;

public class T2584 {

    public int findValidSplit(int[] nums) {
        int right = 1;
        for (int i = 0; i < nums.length; i++) {
            for (int j = right; j < nums.length; j++) {
                if (commonDivisor(nums[i], nums[j]) != 1) {
                    right = j + 1;
                }
            }
            if (i + 1 == right && right != nums.length) {
                return i;
            }
        }
        return -1;
    }

    public int commonDivisor(int a, int b) {
        if (a < b) {
            a = b - a;
            b = b - a;
            a = b + a;
        }
        int c;
        while (a % b != 0) {
            c = a % b;
            a = b;
            b = c;
        }
        return b;
    }

    @Test
    public void test() {
//        int re=commonDivisor(11,6);
//        System.out.println(re);
//[4,7,15,8,3,5]
        int[] ints = {4, 7, 15, 8, 3, 5};
        int f = findValidSplit(ints);
        System.out.println(f);
    }

}
